package com.itheima.test2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*


服务器：收到消息后给出反馈

 */
public class ServerTest {

    public static void main(String[] args) throws IOException {
        //创建对象
        ServerSocket ss = new ServerSocket(10010);
        //建立连接  获取socket 对象
        Socket accept = ss.accept();
        // 接受数据
        InputStream is = accept.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s = reader.readLine();
        //查看数据
        System.out.println(s);

        // 组织数据
        String  s1="瞅你咋地";
        // 回写
        OutputStream os = accept.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        writer.write(s1);
        writer.flush();
        accept.shutdownOutput();
        //释放资源
        ss.close();


    }
}
